package com.shuai.shuaisecondhand_springboot.service;

import com.shuai.shuaisecondhand_springboot.entity.Order;
import com.shuai.shuaisecondhand_springboot.mapper.OrderMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;

    //查询
    public List<Order> findAll() {
        return orderMapper.findAll();
    }

    //根据订单Oid查找所有数据(左外连接)
    public Order getOneOrder(String Oid) {
        return orderMapper.getOneOrder(Oid);
    }

    //根据订单id查找所有数据(数据库的)
    public Order findOne(@Param("Oid") String Oid) {
        return orderMapper.findOne(Oid);
    }

    //根据买家id查找所有数据
    public List<Order> findOneBuy(String buyUid, String Oid) {
        return orderMapper.findOneBuy(buyUid, Oid);
    }

    //买家查询所有数据量
    public int getBuyTotal(String buyUid, String Oid) {
        return orderMapper.getBuyTotal(buyUid, Oid);
    }

    //根据卖家id查找所有数据
    public List<Order> findOneSELL(String sellUid, String Oid) {
        return orderMapper.findOneSell(sellUid, Oid);
    }

    //买家查询所有数据量
    public int getSELLTotal(String sellUid, String Oid) {
        return orderMapper.getSellTotal(sellUid, Oid);
    }

    //插入
    public Boolean insertOrder(String BuyUid, String SellUid, String id, String price) {
        try {
            return orderMapper.insertOrder(BuyUid, SellUid, id, price);
        } catch (Exception e) {
            return false;
        }
    }

    //删除
    public Integer deleteOrder(long id) {
        return orderMapper.deleteOrder(id);
    }

    //批量删除
    public Integer deleteOrderBatch(List<Integer> ids) {
        return orderMapper.deleteOrderBatch(ids);
    }

    //分页查询
    public List<Order> getOrderPage(Integer pageNum, Integer pageSize, String Oid) {
        return orderMapper.getOrderPage(pageNum, pageSize, Oid);
    }

    //查询所有数据量
    public int getTotal(String Oid) {
        return orderMapper.getTotal(Oid);
    }

    //查询订单总数
    public int getAllTotal() {
        return orderMapper.getAllTotal();
    }

    //查询订单总数
    public String getPriceTotal() {
        return orderMapper.getPriceTotal();
    }
}
